import django_filters
from django.db.models import Q

from common.models import Student


class StudentFilter(django_filters.FilterSet):
    # name = django_filters.CharFilter(lookup_expr='startswith')
    # tel = django_filters.CharFilter()
    stu = django_filters.CharFilter(method='name_or_tle')

    @staticmethod
    def name_or_tle(queryset, name, value):
        queryset = queryset.filter(Q(name__contains=value) | Q(tel=value))
        return queryset

    class Meta:
        model = Student
        fields = ('stu', )

